﻿using AspectCore.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using QQ.Client;
using System;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Tars.Net.Clients;

namespace QQ
{
    class Program
    {
        static async Task Main(string[] args)
        {
            Console.WriteLine("欢迎使用未来通讯系统。");
            try
            {
                Assembly.LoadFrom("QQTars.dll");

                var service = new ServiceCollection()
                    .AddSingleton<IConfiguration>(i => new ConfigurationBuilder().AddJsonFile("app.json").Build())
                    .AddConfiguration()
                    //.AddLogging(j => j.AddConsole())
                    .AddQQTcpClient()
                    .AddAop()
                    .BuildDynamicProxyServiceProvider();
                var client = service.GetRequiredService<QQController>();
                //await client.Login(, ""); //see app.json
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            //while (true) { await Task.Delay(1000); }
            //Console.ReadKey();
            var cancellationTokenSource = new CancellationTokenSource();
            AppDomain.CurrentDomain.ProcessExit += (s, e) => cancellationTokenSource.Cancel();
            Console.CancelKeyPress += (s, e) => cancellationTokenSource.Cancel();
            await Task.Delay(-1, cancellationTokenSource.Token).ContinueWith(t => { });
        }
    }
}
